<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
var queryParams = {};
var tables = $('#dataTables').DataTable({
    "sAjaxSource" : '{{ urlfor "CuringController.PlanList"}}'
    ,"bLengthChange": false
    ,"fnServerData" : function(sSource, aoData, fnCallback) {
        queryParams = checkQueryTableData(aoData);
        var form = $('.query-form').serializeArray();
        $.each(form, function(i, value){
            queryParams[value.name] = value.value;
        });
        $.post(sSource, JSON.stringify(queryParams),function(resp) {
            fnCallback(resp);
        },'json')
    }
    ,columns: [
        {render:function(data, type, full, meta) {
            return full.Number;
        }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Name;
        }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                var str = '';
                switch (full.CuringType) {
                    case 1: str= '重点养护'; break;
                    case 2: str= '临时养护'; break;
                }
                return str;
        }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return timetrans(full.CreatedAt);
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.AlreadyCheckNumber+'/'+full.NeedCheckNumber;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                var str = '';
                switch (full.Status) {
                    case 1: str= '养护中'; break;
                    case 2: str= '已完成'; break;
                }
                return str;
            }, "bSortable": false}
        ,{
            "mDataProp": "Action",
            "bSortable": false,
            "sWidth":"10%",
            "render": function ( data, type, full, meta ) {
				if(full.Status == 1) {
					btns = '<a href="{{urlfor "CuringController.CuringProductList"}}/'+ full.Id +'" class="am-btn am-btn-success am-btn-xs">继续养护</a>';
				}else {
					btns = '<a href="{{urlfor "CuringController.CuringProductCheckDetail"}}/'+ full.Id +'" class="am-btn am-btn-success am-btn-xs">查看检查记录</a>';
				}
                return btns;
            }
        }
    ]
    ,"aLengthMenu":[20, 50, 100, 200]
	,'bLengthChange': true
    ,"serverSide": true
    ,"bPaginate" : true
    ,"bFilter" : false	//是否启动过滤、搜索功能
    ,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
    ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
});

$("#query-submit").bind("click", function () { //点击按钮 触发table重新请求服务器
    $("#dataTables").dataTable().fnDraw(false);
    return false;
});

$('#insert-plan').click(function(){
    var url = '{{urlfor "CuringController.PlanCreate"}}';
    layer.open({
        type: 2,
        title: '养护条件设置',
        shadeClose: false,
        shade: 0.2,
        maxmin: false,
        shift: 1,
        area: ['800px', '340px'],
        content: url
    });

    return false;
});

function dialogReback(id) {
    layer.closeAll();
    location = '{{ urlfor "CuringController.CuringProductList"}}/'+id;
}
</script>
